#include <bits/stdc++.h>
using namespace std;

using llt = long long;

llt A, B;
// Dij, i表示位数, j表示前一位
llt D[8][10]; 
vector<int> G;
int const FULL = 10;

llt dfs(int pos, int pre, bool lead, bool limit){
    if(-1 == pos){
        return 1;
    }
    if(not lead and not limit and -1 != D[pos][pre]){
        return D[pos][pre];
    }

    int last = limit ? G[pos] : FULL - 1;
    llt ans = 0;
    for(int i=0;i<=last;++i){
        if(4 == i) continue;
        if(6 == pre and 2 == i) continue;
        ans += dfs(pos - 1, i, lead&&0==i, limit&&last==i);
    }

    if(not lead and not limit){
        D[pos][pre] = ans;
    }
    return ans;
}

llt digitDP(llt n){
    G.clear();
    while(n){
        G.emplace_back(n % FULL);
        n /= FULL;
    }
    auto t = dfs(G.size() - 1, 0, true, true);
    return t;
}

void work(){
    cout << digitDP(B) - digitDP(A - 1) << "\n";
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
    memset(D, -1, sizeof(D));
    int nofkase = 1;
    // cin >> nofkase;
    // while(nofkase--) work();
    while(cin >> A >> B and A and B) {
        work();
    }
	return 0;
}